/*----------------------------------------------------------------------------
 * osObjects.h: CMSIS-RTOS global object definitions for an application
 *----------------------------------------------------------------------------
 * This header file defines global RTOS objects used throughout a project
 * #define osObjectsPublic indicates that objects are defined; without that
 * definition the objects are defined as external symbols.
 *--------------------------------------------------------------------------*/
#ifndef __os_obj__
#define __os_obj__

#ifdef __os_obj_creat__
#define OBJ_EXT
#else
#define OBJ_EXT extern
#endif

#include "RTX_Config.h"
#include "cmsis_os.h" // CMSIS RTOS header file

#ifdef __cplusplus
extern "C"
{
#endif

/*******************************************************************************
 * @brief  API 调试信息
 *******************************************************************************/
#define OS_API_DBG_EN 0

#if (DBG_EN + OS_API_DBG_EN) > 1
#define api_dbg_print dbg_print
#define api_dbg_puts sys_hw_puts
#else
#define api_dbg_print(...)
#define api_dbg_puts(...)
#endif

	extern char *tx_err_txt[];
#if (DBG_EN + OS_API_DBG_EN) > 1
	void os_err_print(uint16_t os_err, char *file, int line);
#define os_api_exe_check() os_err_print(os_err, __FILE__, __LINE__)
#else
#define os_api_exe_check()
#endif

/*******************************************************************************
 * @brief  时基
 *******************************************************************************/
#define ms_ticks(x) ((x * OS_TICK_FREQ + 999) / 1000)

	/*******************************************************************************
	 * @brief  系统对象
	 *******************************************************************************/
	typedef struct
	{
		// global 'thread' functions ---------------------------------------------------
		osThreadId tid_sys_task; // thread id
		osThreadId tid_usb_task; // thread id
		osThreadId tid_mb_task;	 // thread id
		osThreadId tid_flash_task;
		osThreadId tid_sd_task;
		osThreadId tid_str_task;
		osThreadId tid_key_task;
		osThreadId tid_gui_task;
		osThreadId tid_console_task;
		osThreadId tid_nand_task;
		osThreadId tid_crypto;
		osThreadId tid_esp;
		osThreadId tid_gp30;

		// global 'semaphores' ----------------------------------------------------------
		osMutexId mid_eep;
		osMutexId mid_q25;
		osMutexId mid_printf;
		osMutexId mid_malloc;
		osMutexId mid_file;

		// global 'message queues' -------------------------------------------------------

		// global 'mail queues' ----------------------------------------------------------

	} os_obj_type;

	OBJ_EXT os_obj_type os_obj;

	/*******************************************************************************
	 * @brief  thread creat: systask , create befor os start
	 * \param[in] none
	 * \retval: err
	 *******************************************************************************/
	int thread_init(void);

	/*******************************************************************************
	 * @brief  thread creat: created in systask
	 * \param[in] none
	 * \retval: err
	 *******************************************************************************/
	int thread_create(void);

	/*******************************************************************************
	 * @brief  os lock & unlock
	 * \param[in] none
	 * \retval: none
	 *******************************************************************************/
	void os_lock(void);
	void os_unlock(void);

	/*******************************************************************************
	 * @brief  EOF
	 *******************************************************************************/

#ifdef __cplusplus
}
#endif

#endif // __os_obj__
